class MyQueue {
    constructor(capacity) {
        this.arr = new Array(capacity);
        this.front = 0;
        this.rear = 0;
    }
    /**
     * 入队
     * @param element 入队的元素
     */
    enQueue(element) {
        if ((this.rear + 1) / this.arr.length === this.front) {
            throw new Error('队列已满');
        }
        this.arr[this.rear] = element;
        this.rear = (this.rear + 1) % this.arr.length;
    }
    /**
     * 出队
     */
    deQueue() {
        if (this.rear === this.front) {
            throw new Error('队列已空！');
        }
        let deQueueElement = this.arr[this.front];
        this.front = (this.front + 1) % this.arr.length;
        return deQueueElement;
    }
    /**
     * 输出队列
     */
    output() {
        for (
            let i = this.front;
            i != this.rear;
            i = (i + 1) % this.arr.length
        ) {
            console.log(this.arr[i]);
        }
    }
    static main() {
        let myQueue = new MyQueue(6);
        myQueue.enQueue(3);
        myQueue.enQueue(5);
        myQueue.enQueue(6);
        myQueue.enQueue(8);
        myQueue.enQueue(1);
        myQueue.deQueue();
        myQueue.deQueue();
        myQueue.deQueue();
        myQueue.enQueue(2);
        myQueue.enQueue(4);
        myQueue.enQueue(9);
        myQueue.output();
    }
}

MyQueue.main()